import json


class Student(object):
    def __init__(self, number, name, gender, age, grade):
        self.number = number
        self.name = name
        self.gender = gender
        self.age = age
        self.grade = grade

    def change(self, subject, score):
        self.grade[subject] = score

    def average(self):
        result = 0.0
        for score in self.grade.values():
            result += score
        return result / len(self.grade)

    def __eq__(self, other):
        return self.average() == other.average()

    def __lt__(self, other):
        return self.average() < other.average()

    def __gt__(self, other):
        return self.average() > other.average()

    def __str__(self):
        return str(self.__dict__)


def list2StudentList(studentList):
    return [Student(d["number"], d["name"], d["gender"], d["age"], d["grade"]) for d in studentList]


if __name__ == "__main__":
    with open("students.json", "r+") as f:
        students = list2StudentList(json.load(f))
        students.sort()
        for index, student in enumerate(students):
            print(index, student, student.average())
